<template>
  <div class="base-echarts">
    <div ref="echartsDivRef" :style="{ width: width, height: height }"></div>
  </div>
</template>

<script lang="ts" setup>
import { ref, onMounted, defineProps, withDefaults, watchEffect } from 'vue'

import { EChartsOption } from 'echarts'
import useEchart from '../hooks/useEcharts'
//定义props   使用withDefaults实现props默认
const props = withDefaults(
  //使用defineprops定义props
  defineProps<{
    options: EChartsOption
    width?: string
    height?: string
  }>(),
  { width: '100%', height: '360px' }
)
const echartsDivRef = ref<HTMLElement>()
onMounted(() => {
  const { setOptions } = useEchart(echartsDivRef.value!)
  watchEffect(() => {
    setOptions(props.options)
  })
})
</script>

<style scoped></style>
